package com.itheima.health.controller.admin;

import com.itheima.health.common.MessageConst;
import com.itheima.health.pojo.CheckGroup;
import com.itheima.health.pojo.CheckItem;
import com.itheima.health.result.PageResult;
import com.itheima.health.result.QueryPageBean;
import com.itheima.health.result.Result;
import com.itheima.health.service.CheckGroupService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.AutoConfigureOrder;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/checkgroup")
@Slf4j
public class CheckGroupController {
    @Autowired
    private CheckGroupService checkGroupService;
    /*
        新增组
    */
    @PostMapping("/add")
    public Result addGroup(@RequestParam("checkitemIds") List<String> checkitemIds,
                            @RequestBody CheckGroup checkGroup){
        checkGroupService.addGroup(checkGroup,checkitemIds);
        return new Result(true, MessageConst.ADD_CHECKGROUP_SUCCESS);
    }
    /*
    * 分页查询
    * */
    @GetMapping("findPage")
    public Result list(QueryPageBean queryPageBean){
           PageResult pageResult =  checkGroupService.list(queryPageBean);
           return new Result(true,MessageConst.ACTION_SUCCESS,pageResult);
    }
    /*
    * 根据id查询
    * */
    @GetMapping("/findById")
    public Result selectBid(Integer id){
      CheckGroup checkGroup =  checkGroupService.findByid(id);
    return new Result(true,MessageConst.ACTION_SUCCESS,checkGroup);
    }
    /*
    * 根据id查询项目表
    * */
    @GetMapping("/findCheckItemIdsByCheckGroupId")
    public Result findCheckItemIdsByCheckGroupId(Integer id ){
     List<Integer> ids =   checkGroupService.findcheckid(id);
        return new Result(true,MessageConst.ACTION_SUCCESS,ids);
    }
    /*
    * 根据id修改
    * */
    @PostMapping("/edit")
    public Result updateBid(@RequestBody CheckGroup checkGroup,
                            @RequestParam("checkitemIds") List<String> checkitemIds){
        checkGroupService.updateBid(checkGroup,checkitemIds);
        return new Result(true,MessageConst.EDIT_CHECKGROUP_SUCCESS);
    }
    /*
    * 根据id删除
    * */
    @PostMapping("/deleteCheckGroupitemById")
    public Result telectl(Integer id){
        checkGroupService.deteleBid(id);
        return new Result(true,MessageConst.DELETE_CHECKGROUP_SUCCESS);
    }
    /*
    * 查询检查项
    * */
    @GetMapping("/findAll")
    public Result selectGoup(){
      List<CheckGroup> checkGroup =  checkGroupService.selectGoup();
      return  new Result(true,MessageConst.ACTION_SUCCESS,checkGroup);
    }
}
